package fhp.hlhj.giantfold

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AlertDialog
import fhp.hlhj.giantfold.customView.LoadingDialog
import fhp.hlhj.giantfold.event.NetWorkEvent
import fhp.hlhj.giantfold.presenter.BasePresenter
import fhp.hlhj.giantfold.servicess.NetWorkService
import fhp.hlhj.giantfold.utils.LoadingUtils
import fhp.hlhj.giantfold.utils.MyUtils
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

abstract class BaseActivity : AppCompatActivity() {
    lateinit var loadingDialog:LoadingDialog
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        EventBus.getDefault().register(this)
        setContentView(getContentId())
        MyUtils.setWindowStatusBarColor(this,getStatusColor())
        MyUtils.AtyContainer.getInstance().addActivity(this)
        loadingDialog=LoadingUtils.getInstence(this)
        initSet()
        initView()
        initData()
        initListener()
    }

    open fun initData() {

    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }
    private fun initSet() {
        supportActionBar?.hide()
    }
    open fun getStatusColor():Int{
        return R.color.colorPrimaryDark
    }
    protected abstract fun getContentId():Int
    open fun initListener() {

    }
    open fun initView() {
    }

    @Subscribe(threadMode = ThreadMode.POSTING)
    public fun onNetCheck(netWorkService: NetWorkEvent){
        val positiveButton = AlertDialog.Builder(this@BaseActivity).setTitle("没有网络连接了！")
                .setPositiveButton("确定") { dialog, which ->
                    System.exit(0)
                }
        positiveButton.show()
    }
}
